<?php

define( 'WEBROOT', dirname( dirname( __FILE__ ) ) . '/' );
define( 'WEBLIB', WEBROOT . 'system/lib/' );
define( "WEBTPL", WEBROOT . "content/tpl/" );
define( "WEBCACHE", WEBROOT . "content/cache/" );
define( 'DEBUG', true );
define( 'MODE', 0766 );

header( 'Content-Type: text/html; charset=UTF-8' );
date_default_timezone_set( 'PRC' );
ob_start();
session_start();

if ( DEBUG ) {
    if ( substr( PHP_VERSION, 0, 3 ) == "5.3" ) {
        error_reporting( E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED );
    } else {
        error_reporting( E_ALL & ~E_NOTICE & ~E_WARNING );
    }
} else {
    error_reporting( 0 );
}

if ( get_magic_quotes_gpc() ) {
    $_GET = dostripslashes( $_GET );
    $_POST = dostripslashes( $_POST );
    $_COOKIE = dostripslashes( $_COOKIE );
    $_REQUEST = dostripslashes( $_REQUEST );
}

function dostripslashes( $value ) {
    $value = is_array( $value ) ? array_map( 'dostripslashes', $value ) : stripslashes( $value );
    return $value;
}

# 加载核心库
require_once WEBLIB . 'base.php';
require_once WEBLIB . 'db.php';
require_once WEBLIB . 'kernel.php';
require_once WEBLIB . 'cache.php';
require_once WEBLIB . 'paged.php';
require_once WEBLIB . 'template.php';

$c = G( 'c', 'main' );
$a = G( 'a', 'index' );

# 检查程序是否安装
if ( !file_exists( WEBROOT . 'system/config.php' ) && !strpos( getRequest( 'REQUEST_URI' ), 'install' ) ) {
    header( "location: /install" );
}

# 加载配置文件
if ( file_exists( WEBROOT . 'system/config.php' ) ) {
    require_once WEBROOT . 'system/config.php';
}

filter();